package com.gkt.ec.ws.activity.dao;

import com.gkt.ec.commons.shared.persistence.annotation.MyBatisDao;
import com.gkt.ec.ws.activity.model.domain.CompanyActivityEntity;
import com.gkt.ec.ws.activity.model.domain.CustomerActivityEntity;
import com.gkt.ec.ws.activity.model.domain.MarketActivityEntity;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author Huzl
 * @version 1.0.0
 */
@MyBatisDao
public interface CustomerActivityDao {
    @Select("SELECT id, activity_name, activity_type, activity_desc, activity_url, is_limited, limit_number," +
            " attend_notify_sms_template,attend_user_count,start_time, end_time, activity_area, activity_location, " +
            " sms_send_type, verify_type from tb_ec_market_activity " +
            " where is_deleted=0 and id=#{activityId}")
    MarketActivityEntity getActivity(Long activityId);

    @Select("select id,activity_id, custom_id, vehicle_id, customer_tel, vehicle_license, vehicle_brand, " +
            " verify_code,verify_status from tb_ec_customer_activity where id=#{customerActivityId}")
    CustomerActivityEntity getCustomerActivity(Long customerActivityId);

    @Select("select  id,activity_id, custom_id, vehicle_id, customer_tel, vehicle_license, vehicle_brand, " +
            " verify_code,verify_status  from tb_ec_customer_activity where verify_code=#{verifyCode}")
    CustomerActivityEntity getCustomerActivityByVerifyCode(String verifyCode);

    @Select("select  id,activity_id, custom_id, customer_tel,vehicle_license,verify_code,verify_status from tb_ec_customer_activity" +
            " where id=#{customerActivityId} and customer_tel=#{phone}")
    CustomerActivityEntity getCustomerActivityByPhone(@Param("customerActivityId") Long activityId,
                                                      @Param("phone") String phone);

    @Update("update tb_ec_customer_activity set verify_code=#{verifyCode},verify_status=1,user_verify_time=now()  where id=#{id}")
    void updateVerifyCode(@Param("id") Long customerActivityId, @Param("verifyCode") String verifyCode);

    @Update("update tb_ec_customer_activity set verify_status=#{verifyStatus},company_verify_time=now(),company_id=#{companyId}  where id=#{id}")
    void updateCompanyVerifyStatus(@Param("id") Long customerActivityId, @Param("verifyStatus") int verifyStatus, @Param("companyId") Long companyId);

    @Update("update tb_ec_market_activity set attend_user_count=attend_user_count+1  where id=#{activityId}")
    void increaseAttendUserCount(Long activityId);

    @Select("select activity_id,company_id from tb_ec_company_activity where activity_id=#{activityId} and company_id=#{companyId}")
    CompanyActivityEntity getCompanyActivity(@Param("activityId") Long activityId, @Param("companyId") Long companyId);

}
